package com.bana.sys.controller;

import com.bana.sys.code.DatabaseResult;
import com.bana.sys.dao.ParameterDAO;
import com.bana.sys.utils.*;
import com.bana.sys.model.Parameter;
import com.bana.sys.service.ParameterService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/parameter",method = RequestMethod.POST)
public class ParameterController {

    @Resource
    private ParameterDAO parameterDAO;

    @Resource
    private ParameterService parameterService;


    /**
     * 查询参数集合
     * @param request 分页
     * @return
     */
    @RequestMapping(value = "getParameters.do",method = RequestMethod.POST)
    public PageResponse<Parameter> getParameters(@RequestBody TokenRequest<PageParameter> request){

        List<Parameter> parameters = parameterDAO.getParameters(request.getData());
        int count=parameterDAO.getParameterCount();
        return new PageResponse<>(parameters,count);
    }

    /**
     * 更新参数
     * @param request 参数
     * @return
     */
    @RequestMapping(value = "/updateParameter.do", method = RequestMethod.POST)
    public ActionResult updateParameter(@RequestBody TokenRequest<Parameter> request) {

        ActionResult actionResult=new ActionResult();
        parameterService.updateParameter(request.getToken(),request.getData());
        actionResult.setCzjg(DatabaseResult.Success);
        return actionResult;
    }

}
